import {defineEventHandler} from "h3";
import path from "path";
import fs from 'fs';
const getAllFiles = (dirPath: string) => {
    const files = fs.readdirSync(dirPath);
    let allFiles: any[] = [];

    files.forEach(file => {
        const filePath = path.join(dirPath, file);
        const fileStat = fs.statSync(filePath);

        if (fileStat.isFile()) {
            allFiles.push(filePath);
        }
        if (fileStat.isDirectory()) {
            allFiles = allFiles.concat(getAllFiles(filePath));
        }
    });
    return allFiles;
}
export default defineEventHandler(async (event) => {
    try {
        const folderPath = `${process.cwd()}/public/mds`;
        const files = getAllFiles(folderPath).map(v => v.slice(folderPath.length + 1));
        console.log(files);
        return files;
    } catch (e) {
        return e;
    }
})
